package mylab.usm.oauth2.client.controller;

import com.fujieid.jap.core.config.AuthenticateConfig;
import com.fujieid.jap.oauth2.OAuthConfig;
import com.fujieid.jap.oauth2.Oauth2GrantType;
import me.zhyd.oauth.utils.UuidUtils;
import mylab.usm.oauth2.client.config.AuthProperties;
import mylab.usm.oauth2.client.config.AuthStrategy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 使用第三方OAuth2.0服务之客户端凭证模式（适用于没有前端的命令行应用）
 * 需要依赖 jap-oauth2 模块
 */
@RestController
@RequestMapping("/oauth2/client")
public class Oauth2ClientController extends BaseOAuth2Controller {

    @Override
    protected AuthStrategy getAuthStrategy() {
        return AuthStrategy.oauth2_client_credentials;
    }

    @Override
    protected AuthenticateConfig getAuthenticateConfig(AuthProperties.Platform platform) {
        return new OAuthConfig()
                .setPlatform(platform.getPlatformId())
                .setState(UuidUtils.getUUID())
                .setClientId(platform.getClientId())
                .setClientSecret(platform.getClientSecret())
                .setGrantType(Oauth2GrantType.CLIENT_CREDENTIALS);
    }

}
